//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using Eas.WebCrawler.Interfaces;

namespace Eas.WebCrawler.Test.Model {

    public class RequestStoreTestEvents : Eas.WebCrawler.Interfaces.WebCrawlerEvents {

        /// <summary>Fired when the UrlBeganProcessing event occurs.</summary>
        public event System.EventHandler<ProcessingStateEventArgs> UrlBeganProcessing;

        /// <summary>Fires when the UrlBeganProcessing event.</summary>
        public void Fire_UrlBeganProcessing(ProcessingStateEventArgs argument) {
            if (UrlBeganProcessing != null) {
                UrlBeganProcessing(this, argument);
            }
        }

        /// <summary>Fired when the Starting event occurs.</summary>
        public event System.EventHandler Starting;

        /// <summary>Fires when the Starting event.</summary>
        public void Fire_Starting() {
            if (Starting != null) {
                Starting(this, new System.EventArgs());
            }
        }

        /// <summary>Fired when the Stopped event occurs.</summary>
        public event System.EventHandler Stopped;

        /// <summary>Fires when the Stopped event.</summary>
        public void Fire_Stopped() {
            if (Stopped != null) {
                Stopped(this, new System.EventArgs());
            }
        }

        /// <summary>Fired when the Paused event occurs.</summary>
        public event System.EventHandler Paused;

        /// <summary>Fires when the Paused event.</summary>
        public void Fire_Paused() {
            if (Paused != null) {
                Paused(this, new System.EventArgs());
            }
        }

        /// <summary>Fired when the Unpausing event occurs.</summary>
        public event System.EventHandler Unpausing;

        /// <summary>Fires when the Unpausing event.</summary>
        public void Fire_Unpausing() {
            if (Unpausing != null) {
                Unpausing(this, new System.EventArgs());
            }
        }

        /// <summary>Fired when the UrlProcessed event occurs.</summary>
        public event System.EventHandler<UrlCompletedEventArgs> UrlProcessed;

        /// <summary>Fires when the UrlProcessed event.</summary>
        private void Fire_UrlProcessed(UrlCompletedEventArgs argument) {
            if (UrlProcessed != null) {
                UrlProcessed(this, argument);
            }
        }

        /// <summary>Fired when the Trace event occurs.</summary>
        public event System.EventHandler<ProcessingStateMessageEventArgs> OnTrace;

        /// <summary>Fires when the OnTrace event.</summary>
        public void Fire_OnTrace(int id, string argument) {
            using (TestProcessingState state = new TestProcessingState(id)) {
                if (OnTrace != null) {
                    OnTrace(this, new ProcessingStateMessageEventArgs(state, argument));
                }
            }
        }

        /// <summary>Fired when the Error event occurs.</summary>
        public event System.EventHandler<ProcessingStateMessageEventArgs> OnError;

        /// <summary>Fires when the OnError event.</summary>
        public void Fire_OnError(int id, string argument) {
            using (TestProcessingState state = new TestProcessingState(id)) {
                if (OnError != null) {
                    OnError(this, new ProcessingStateMessageEventArgs(state, argument));
                }
            }
        }

        /// <summary>Fired when the UrlFailed event occurs.</summary>
        public event System.EventHandler<Eas.WebCrawler.Interfaces.UrlFailedEventArgs> UrlFailed;

        /// <summary>Fires when the UrlFailed event.</summary>
        private void Fire_UrlFailed(Eas.WebCrawler.Interfaces.UrlFailedEventArgs argument) {
            if (UrlFailed != null) {
                UrlFailed(this, argument);
            }
        }



        #region WebCawlerEvents Members


        public TraceLevel TraceLevel {
            get { return TraceLevel.All; }
            set { }
        }

        #endregion
    }

    public class RequestStoreTestContext : Eas.WebCrawler.Common.BaseDisposable, Eas.WebCrawler.Interfaces.WebCrawlerContext {
        public Eas.WebCrawler.Interfaces.WebCrawlerContext DelegatedContext;
        public RequestStoreTestEvents _Events = new RequestStoreTestEvents();

        #region WebCrawlerContext Members

        public void Initialize(Eas.WebCrawler.Interfaces.WebCrawlerEvents events) { }

        public Eas.WebCrawler.Interfaces.WebCrawlerEvents Events {
            get { return _Events; }
        }

        public Eas.WebCrawler.Interfaces.RequestStore Store {
            get { return DelegatedContext.Store; }
        }

        public Eas.WebCrawler.Interfaces.CompletedRequestHistory CompletedRequestHistory {
            get { return DelegatedContext.CompletedRequestHistory; }
        }

        #endregion

        #region WebCrawlerSettings Members

        public IComparer<Eas.WebCrawler.Interfaces.Request> RequestPriorityComparer {
            get { return DelegatedContext.RequestPriorityComparer; }
        }

        public Eas.WebCrawler.Interfaces.LinkExtractor LinkExtractor {
            get { return DelegatedContext.LinkExtractor; }
        }

        public int WorkerCount {
            get { return DelegatedContext.WorkerCount; }
        }

        public IEnumerable<string> StartingUris {
            get { return DelegatedContext.StartingUris; }
        }

        public Eas.WebCrawler.Interfaces.LinkSelector Selector {
            get { return DelegatedContext.Selector; }
        }

        public Eas.WebCrawler.Interfaces.TemporaryStorageFactory StorageFactory {
            get { return DelegatedContext.StorageFactory; }
        }

        public int SleepTimeInMilliseconds {
            get { return DelegatedContext.SleepTimeInMilliseconds; }
        }

        public int TimeoutInMilliseconds {
            get { return DelegatedContext.TimeoutInMilliseconds; }
        }

        #endregion
    }
}
